package com.example.demo0331.controller;

import com.example.demo0331.entity.User;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class PostController {

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public User user(Integer id, String name, Integer age) {
        User u = new User();
        u.setId(id);
        u.setName(name);
        u.setAge(age);
        return u;
    }

    @RequestMapping(value = "/user1", method = RequestMethod.POST)
    public User user1(User user) { // 只能接受form-data或formurlencode格式参数
        return user;
    }

    @RequestMapping(value = "/jsonUser", method = RequestMethod.POST)
    public User jsonUser(@RequestBody User user) { // 必须加上注解才能接受json格式参数
        return user;
    }
}
